package Course11;

import java.util.HashMap;
import java.util.Map;

public class Hash {
    public static void main(String[] args) {
        Map<String,Teacher>hashMap1=new HashMap<>();
        Map<String,Teacher>hashMap2=new HashMap<>();
        Teacher yebing=new Teacher();
        Teacher jiaoge=new Teacher();
        Teacher ff=new Teacher();
        yebing.setAge(18);
        yebing.seyName("叶冰");
        hashMap1.put(yebing.getName(),yebing);

        jiaoge.setAge(28);
        jiaoge.seyName("焦哥");
        hashMap1.put(jiaoge.getName(),jiaoge);

        ff.setAge(20);
        ff.seyName("樊凡");
        hashMap2.put(ff.getName(),ff);
        String str="叶冰";

        System.out.println(hashMap1.get(str).getAge());
        System.out.println("HashMap1的元素个数是"+hashMap1.size());

        Map<String,Map<String,Teacher>>hashMap4=new HashMap<>();
        hashMap4.put("pku",hashMap1);
        hashMap4.put("alibaba",hashMap2);
        System.out.println(hashMap4.get("pku").get("叶冰").getAge());

        //遍历方法1
        /*Iterator iter=hashMap1.entrySet().iterator();
        while(iter.hasNext()){
            Map.Entry name=(Map.Entry)iter.next();
            String nameKey=(String)name.getKey();
            String nameValue=(String)name.getValue();
            System.out.println(nameKey+"'s name is"+nameValue);
        }*/
        //遍历方法2
        /*hashMap1.forEach((key,value)->{
            System.out.println("[key=" + key + ",value=" + value + "]");
        })*/

    }
}
